Rename types like RGBA_Array_Float
to FloatRGBA
and add types like FloatRGBA_Array
#4386
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview: What does this pull request change?
Make the following changes:
X_Array_Float
->FloatX
(example:RGBA_Array_Float
is renamed toFloatRGBA
)X_Array_Int
->IntX
(example:RGBA_Array_Int
is renamed toIntRGBA
)X_Tuple_Float = tuple[float, ...]
->FloatXLike = Union[FloatX, tuple[float, ...]
(example:RGBA_Tuple_Float = tuple[float, float, float, float]
was changed toFloatRGBALike = Union[FloatRGBA, tuple[float, float, float, float]]
. This is for consistency with types such asPoint3DLike
, which are unions.)X_Tuple_Int = tuple[int, ...]
->IntXLike = Union[IntX, tuple[int, ...]
in order to add some color array types:
FloatRGBA_Array
is a NumPy array of shape(M, 4)
containing M rows representing RGBA colors.FloatRGBALike_Array
is anything which can be converted to aFloatRGBA_Array
, including lists of colors, for example.FloatRGB_Array
andFloatRGBLikeArray
are the same, but for RGB colors.and properly type multiple parameters, returned values and other variables which correspond to NumPy arrays of colors.
Motivation and Explanation: Why and how do your changes improve the library?
Many parameters, returned values and other variables around the source code were 2D NumPy arrays of multiple colors and their type hints were incorrect. Specifically,
npt.NDArray[RGBA_Array_Float]
is invalid, sinceRGBA_Array_Float
is not really a valid or correct dtype in this case (it should be a float). This indicates that we need type aliases for arrays of colors.However, the current names weren't ideal for this task, because, if we have
RGBA_Array_Float
for a single color, its corresponding type alias for array of colors would beRGBA_Array_Float_Array
, which is a strange name: it's too long and contains the wordArray
twice, which is confusing. Therefore, I also needed to rename those aliases.Links to added or changed documentation pages
There are too many type changes around the code, so listing all of them is not very practical. Instead, I'll just link the
typing
webpage:https://manimce--4386.org.readthedocs.build/en/4386/reference/manim.typing.html
Reviewer Checklist